/**
 * @file e1_t2_q5.c
 * @date 2022-03-01
 * 
 * @copyright Copyright (c) 2022 cnzyx MIT Licence
 * 
 */

#include<stdio.h>
#include<stdlib.h>

double PI(double acc){
    double result=0,den=1;
    for(long i=0;(1/den)>acc;i++,den+=2){
        if(i%2==0){
            result+=1/den;
        }
        else{
            result-=1/den;
        }
    }
    return result*4;
}

int main(int argc, char const *argv[])
{
    //UTF-8
    system("chcp 65001");
    double acc,result;
    printf("请输入精度值：");
    scanf("%lf",&acc);
    result=PI(acc);
    printf("PI约为：%lf\n",result);

    //Pause console
    system("pause");
    return 0;
}
